<?php

namespace Dao;
/**
 *@api DB::run=>什么语句都可以跑；DB::update更新自动排序参数（局限基本sql）; DB::insert=>录入自动排序参数（局限基本sql）
 *@api 引用laravel DB::select()思想 实现TS静态方法调用trait单例
 *@api DB::update 形似这种 `name`=?, 参数之间需留空格！
 */
class UserDao {
    use \Utils\Facade;
    const Facade = UserMapper::class;
}
//用户Mapper
class UserMapper extends BaseDao {
    public function selUser($name, $ucid, $flag, $pageNum, $pageSize) {
        return [DB::select(" SELECT * FROM tb_user WHERE `name` LIKE concat('%',?,'%') AND ucid LIKE concat('%',?,'%') AND flag LIKE concat('%',?,'%')  ORDER BY uid DESC limit ?,? ", [$name, $ucid, $flag, $pageNum, $pageSize]) ,
                DB::select(" SELECT COUNT(*) AS total FROM tb_user WHERE `name` LIKE concat('%',?,'%') AND ucid LIKE concat('%',?,'%') AND flag LIKE concat('%',?,'%') ", [$name, $ucid, $flag]) [0]->total];
    }
    public function editUser($data) {
        return DB::update(" UPDATE tb_user SET `name`=?, `flag`=? WHERE uid=? ", $data);
    }
    public function addUser($data) {
        return DB::insert(" INSERT INTO tb_user (account,password,name,flag,ucid) VALUES (?,?,?,?,?) ", $data);
    }
    public function delUser($ids) {
        return DB::delete(" DELETE FROM tb_user WHERE uid IN (?) ", $ids);
    }
}
